package com.huawei.hianalytics.log.e;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Process;
import android.text.TextUtils;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import com.huawei.hianalytics.g.b;
import com.huawei.hms.framework.common.ContainerUtils;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class f {
    public static String a() {
        return Process.myPid() + "_" + c() + ".log";
    }

    public static void a(Context context, String str) {
        float f = 3.0f;
        try {
            float parseFloat = Float.parseFloat(str.split(ContainerUtils.KEY_VALUE_DELIMITER)[1].trim());
            if (parseFloat <= 3.0f) {
                f = parseFloat < 0.0f ? 0.0f : parseFloat;
            }
        } catch (NumberFormatException e) {
            b.d("AppLogApi/LogUtil", "The cycle of the server returns : " + str);
            f = 1.0f;
        }
        b.b("AppLogApi/LogUtil", "setpolicy cycle : " + f);
        c.a(c.b(context), "autocheck_policy", Float.valueOf(1.0f));
    }

    public static boolean a(Context context) {
        if (context == null) {
            b.c("AppLogApi/LogUtil", "No init of logServer!");
            return false;
        }
        boolean z;
        long currentTimeMillis = System.currentTimeMillis();
        SharedPreferences b = c.b(context);
        long longValue = ((Long) c.b(b, "autocheck_starttime", Long.valueOf(-1))).longValue();
        b.b("AppLogApi/LogUtil", "checkPolicyOver beforeTimeMillis : " + longValue);
        if (-1 == longValue) {
            b.c("AppLogApi/LogUtil", "checkPolicyOver beforeTimeMillis is first!");
            z = true;
        } else {
            float floatValue = ((Float) c.b(b, "autocheck_policy", Float.valueOf(SizeModifier.STABLE_STATE_SCALE))).floatValue();
            long j = (long) (8.64E7f * floatValue);
            b.b("AppLogApi/LogUtil", "checkPolicyOver policy : " + floatValue);
            if (SizeModifier.STABLE_STATE_SCALE == floatValue) {
                c.a(b, "autocheck_policy", Float.valueOf(1.0f));
                z = true;
            } else {
                z = currentTimeMillis - longValue > j;
            }
        }
        b.b("AppLogApi/LogUtil", "checkPolicyOver() No upload cycle :  " + z);
        return z;
    }

    public static boolean a(String str) {
        File file = new File(str);
        return !file.exists() ? file.mkdirs() : true;
    }

    public static boolean a(File[] fileArr) {
        int length = fileArr.length;
        int i = 0;
        while (i < length) {
            File file = fileArr[i];
            if (file.getName().contains("Crash")) {
                i++;
            } else {
                if (file.delete()) {
                    b.c("AppLogApi/LogUtil", "Logzips folder is larger than 1.8M, and the first file is deleted. ");
                }
                return true;
            }
        }
        return false;
    }

    public static boolean a(File[] fileArr, File file) {
        return b(fileArr, file);
    }

    public static int b(File[] fileArr) {
        int i = 0;
        int length = fileArr.length;
        for (File file : fileArr) {
            String path = file.getPath();
            if (!(path.endsWith(".log") || path.endsWith(".zip"))) {
                if (file.delete()) {
                    i++;
                    b.b("HiAnalytics/logServer", "del filter file :");
                } else {
                    b.b("HiAnalytics/logServer", "del file failed.");
                }
            }
        }
        return length - i;
    }

    public static String b() {
        return new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS", Locale.getDefault()).format(Calendar.getInstance().getTime());
    }

    public static void b(String str) {
        if (!TextUtils.isEmpty(str) && !new File(str).delete()) {
            b.d("AppLogApi/LogUtil", "delete file fail");
        }
    }

    public static boolean b(Context context) {
        if (context == null) {
            b.d("AppLogApi/LogUtil", "No init of logServer!");
            return false;
        }
        boolean z;
        SharedPreferences b = c.b(context);
        long currentTimeMillis = System.currentTimeMillis();
        long longValue = ((Long) c.b(b, "autocheck_tenminstarttime", Long.valueOf(-1))).longValue();
        b.b("AppLogApi/LogUtil", "checkTimeOver beforeTimeMillis : " + longValue);
        if (-1 == longValue || (currentTimeMillis - longValue > 600000 && c(context))) {
            c.a(b, "autocheck_tenminstarttime", Long.valueOf(currentTimeMillis));
            b.b("AppLogApi/LogUtil", "setTenMinAutoCheckTime!");
            z = true;
        } else {
            z = false;
        }
        b.c("AppLogApi/LogUtil", "checkTimeOver " + z);
        return z;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static synchronized boolean b(java.io.File[] r17, java.io.File r18) {
        /*
        r6 = com.huawei.hianalytics.log.e.f.class;
        monitor-enter(r6);
        r5 = 0;
        r2 = 0;
        r3 = 1024; // 0x400 float:1.435E-42 double:5.06E-321;
        r7 = new byte[r3];	 Catch:{ all -> 0x00a7 }
        r3 = new java.io.FileOutputStream;	 Catch:{ FileNotFoundException -> 0x00c5, all -> 0x00ba }
        r0 = r18;
        r3.<init>(r0);	 Catch:{ FileNotFoundException -> 0x00c5, all -> 0x00ba }
        r4 = new java.util.zip.ZipOutputStream;	 Catch:{ FileNotFoundException -> 0x00c9, all -> 0x00c2 }
        r4.<init>(r3);	 Catch:{ FileNotFoundException -> 0x00c9, all -> 0x00c2 }
        if (r17 == 0) goto L_0x00b0;
    L_0x0017:
        r0 = r17;
        r2 = r0.length;	 Catch:{ FileNotFoundException -> 0x0082 }
        if (r2 <= 0) goto L_0x00b0;
    L_0x001c:
        r5 = 0;
        r0 = r17;
        r8 = r0.length;	 Catch:{ FileNotFoundException -> 0x0082 }
        r2 = 0;
        r16 = r2;
        r2 = r5;
        r5 = r16;
    L_0x0026:
        if (r5 >= r8) goto L_0x00b0;
    L_0x0028:
        r9 = r17[r5];	 Catch:{ FileNotFoundException -> 0x0082 }
        r10 = r9.length();	 Catch:{ FileNotFoundException -> 0x0082 }
        r10 = (double) r10;	 Catch:{ FileNotFoundException -> 0x0082 }
        r12 = 4700857291049323725; // 0x413ccccccccccccd float:-1.07374184E8 double:1887436.8;
        r10 = (r10 > r12 ? 1 : (r10 == r12 ? 0 : -1));
        if (r10 <= 0) goto L_0x0048;
    L_0x0038:
        r9 = r9.delete();	 Catch:{ FileNotFoundException -> 0x0082 }
        if (r9 == 0) goto L_0x0045;
    L_0x003e:
        r9 = "AppLogApi/LogUtil";
        r10 = "Delete a file larger than 1.8M";
        com.huawei.hianalytics.g.b.b(r9, r10);	 Catch:{ FileNotFoundException -> 0x0082 }
    L_0x0045:
        r5 = r5 + 1;
        goto L_0x0026;
    L_0x0048:
        r10 = new java.io.FileInputStream;	 Catch:{ FileNotFoundException -> 0x0082 }
        r10.<init>(r9);	 Catch:{ FileNotFoundException -> 0x0082 }
        r11 = new java.util.zip.ZipEntry;	 Catch:{ IOException -> 0x0075 }
        r12 = r9.getName();	 Catch:{ IOException -> 0x0075 }
        r11.<init>(r12);	 Catch:{ IOException -> 0x0075 }
        r4.putNextEntry(r11);	 Catch:{ IOException -> 0x0075 }
        r12 = r9.length();	 Catch:{ IOException -> 0x0075 }
        r14 = (long) r2;	 Catch:{ IOException -> 0x0075 }
        r12 = r12 + r14;
        r12 = (double) r12;	 Catch:{ IOException -> 0x0075 }
        r14 = 4700857291049323725; // 0x413ccccccccccccd float:-1.07374184E8 double:1887436.8;
        r9 = (r12 > r14 ? 1 : (r12 == r14 ? 0 : -1));
        if (r9 > 0) goto L_0x0095;
    L_0x0069:
        r9 = r10.read(r7);	 Catch:{ IOException -> 0x0075 }
        if (r9 <= 0) goto L_0x0095;
    L_0x006f:
        r2 = r2 + r9;
        r11 = 0;
        r4.write(r7, r11, r9);	 Catch:{ IOException -> 0x0075 }
        goto L_0x0069;
    L_0x0075:
        r9 = move-exception;
        r9 = "AppLogApi/LogUtil";
        r11 = "createLogZipWithLock() Stream Exception!";
        com.huawei.hianalytics.g.b.d(r9, r11);	 Catch:{ all -> 0x00aa }
        r9 = 1;
        com.huawei.hianalytics.log.e.d.a(r9, r10);	 Catch:{ FileNotFoundException -> 0x0082 }
        goto L_0x0045;
    L_0x0082:
        r2 = move-exception;
    L_0x0083:
        r2 = "HiAnalytics/logServer";
        r5 = "checkUploadLog,file not found !";
        com.huawei.hianalytics.g.b.c(r2, r5);	 Catch:{ all -> 0x009d }
        r2 = 0;
        r5 = 5;
        com.huawei.hianalytics.log.e.d.a(r5, r4);	 Catch:{ all -> 0x00a7 }
        r4 = 6;
        com.huawei.hianalytics.log.e.d.a(r4, r3);	 Catch:{ all -> 0x00a7 }
    L_0x0093:
        monitor-exit(r6);
        return r2;
    L_0x0095:
        r4.flush();	 Catch:{ IOException -> 0x0075 }
        r9 = 1;
        com.huawei.hianalytics.log.e.d.a(r9, r10);	 Catch:{ FileNotFoundException -> 0x0082 }
        goto L_0x0045;
    L_0x009d:
        r2 = move-exception;
    L_0x009e:
        r5 = 5;
        com.huawei.hianalytics.log.e.d.a(r5, r4);	 Catch:{ all -> 0x00a7 }
        r4 = 6;
        com.huawei.hianalytics.log.e.d.a(r4, r3);	 Catch:{ all -> 0x00a7 }
        throw r2;	 Catch:{ all -> 0x00a7 }
    L_0x00a7:
        r2 = move-exception;
        monitor-exit(r6);
        throw r2;
    L_0x00aa:
        r2 = move-exception;
        r5 = 1;
        com.huawei.hianalytics.log.e.d.a(r5, r10);	 Catch:{ FileNotFoundException -> 0x0082 }
        throw r2;	 Catch:{ FileNotFoundException -> 0x0082 }
    L_0x00b0:
        r2 = 5;
        com.huawei.hianalytics.log.e.d.a(r2, r4);	 Catch:{ all -> 0x00a7 }
        r2 = 6;
        com.huawei.hianalytics.log.e.d.a(r2, r3);	 Catch:{ all -> 0x00a7 }
        r2 = 1;
        goto L_0x0093;
    L_0x00ba:
        r3 = move-exception;
        r4 = r5;
        r16 = r2;
        r2 = r3;
        r3 = r16;
        goto L_0x009e;
    L_0x00c2:
        r2 = move-exception;
        r4 = r5;
        goto L_0x009e;
    L_0x00c5:
        r3 = move-exception;
        r3 = r2;
        r4 = r5;
        goto L_0x0083;
    L_0x00c9:
        r2 = move-exception;
        r4 = r5;
        goto L_0x0083;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hianalytics.log.e.f.b(java.io.File[], java.io.File):boolean");
    }

    private static String c() {
        return new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.getDefault()).format(Calendar.getInstance().getTime());
    }

    private static boolean c(Context context) {
        if (context == null || context.getPackageManager().checkPermission("android.permission.ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
            b.c("HiAnalytics/logServer", "not have network state phone permission!");
            return false;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager == null) {
            return false;
        }
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        boolean z = activeNetworkInfo != null && activeNetworkInfo.isConnected() && activeNetworkInfo.isAvailable();
        return z;
    }
}
